﻿using Cxuu.Common;
using Cxuu.Models;
using Cxuu.Repository;
using PetaPoco;
using System.Threading.Tasks;

namespace Cxuu.Service
{
    [AppService]
    public class ArticleDocreceivedService
    {
        private readonly ArticleDocreceivedRepository  _articleDocreceived;

        public ArticleDocreceivedService(ArticleDocreceivedRepository  articleDocreceived)
        {
            _articleDocreceived = articleDocreceived;
        }

        /// <summary>
        /// 后台编辑一条信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<EditArticleDocreceived> GetEditAsync(int? id)
        {
            return await _articleDocreceived.GetEditAsync(id);
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="articleQuery"></param>
        /// <returns></returns>
        public async Task<Page<ViewArticleDocreceivedAndCate>> GetListByCidAdminAsync(ArticleDocreceivedQuery articleQuery)
        {
            articleQuery.Orderby = "Id desc";
            return await _articleDocreceived.GetListAsync(articleQuery);
        }

        /// <summary>
        /// 写一条新的内容
        /// </summary>
        /// <returns></returns>
        public virtual async Task<ArticleDocreceived> InsertArticleAndContentAsync(ArticleDocreceived articleDocreceived)
        {
            return await _articleDocreceived.InsertArticleAndContentAsync(articleDocreceived);
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <returns></returns>
        public virtual async Task<int> UpdateArticleAndContentAsync(EditArticleDocreceived articleDocreceived)
        {
            return await _articleDocreceived.UpdateArticleAndContentAsync(articleDocreceived);
        }


        /// <summary>
        /// 删除一条信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual async Task<int> DelArticleAndContentAsync(int id)
        {
            if (await _articleDocreceived.DeleteByPriKeyAsync(id) > 0)
            {
                await _articleDocreceived.DeleteByPriKeyAsync(id);
                return 1;
            }
            return 0;
        }
    }
}
